// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import VueRouter from 'vue-router'
import routes from './routes'
import store from './vuex/store'

// import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'

import './assets/css/common.css'
import './assets/css/element-ui.css'
// import './assets/css/mess.css'
import _g from './assets/js/global'
import axios from 'axios'
import 'vue-event-calendar/dist/style.css'
import vueEventCalendar from 'vue-event-calendar'
import Lockr from 'lockr'
import qs from 'qs'

const router = new VueRouter({
  // mode: 'history',
  base: __dirname,
  routes
})
router.afterEach(transition => {
  _g.closeGlobalLoading()
})


router.beforeEach((to,from,next)=>{
  // console.log(to,from)

 if(to.path=="/center"){
   bus.$emit("flashAll")
  next()
 }else if(to.path!='/login'){
    axios.get(PATH+'users/checkLogin').then(res=>{
      if(!res.data){
        router.replace('/login')
      }else{
        next()
      }
    })
  }else{
    next()
  }
})

Vue.prototype.apiPost=_g.apiPost

Vue.config.productionTip = false

Vue.use(VueRouter)
// Vue.use(ElementUI)
//日历组件
Vue.use(vueEventCalendar, {locale: 'zh', color: '#3f9ce2'})

// 引入echarts
// import echarts from 'echarts'
// Vue.prototype.$echarts = echarts

//二维码组件
import QRCode from 'qrcode'
Vue.use(QRCode)
window.QRCode = QRCode

window.router = router
window.store = store
window._g = _g
window.axios = axios
window.Lockr = Lockr
window.qs = qs

window.PATH = '/api/'
// window.PATH = 'index.php/admin/'

const bus = new Vue()
window.bus = bus

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
